/*
 * Copyright (C) 2010- Peer internet solutions
 * 
 * This file is part of mixare.
 * 
 * This program is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details. 
 * 
 * You should have received a copy of the GNU General Public License along with 
 * this program. If not, see <http://www.gnu.org/licenses/>
 */

#import "MarkerView.h"

@implementation MarkerView

@synthesize viewTouched, titleLabel;
@synthesize isHighLight;

- (id)initWithFrame:(CGRect)frame image:(NSString *)image {
    if (self = [super initWithFrame:frame]) {
        
//        titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,0,self.bounds.size.width-20,self.bounds.size.height/2)];
//        titleLabel.backgroundColor = [UIColor clearColor];
//        titleLabel.numberOfLines = 0;
//        titleLabel.font = [UIFont systemFontOfSize:11];
//        titleLabel.textAlignment = NSTextAlignmentLeft;
//        titleLabel.textColor = [UIColor whiteColor];
//        [self addSubview:titleLabel];
//        
//        _distanceLable = [[UILabel alloc] initWithFrame:CGRectMake(10,self.bounds.size.height/2,self.bounds.size.width-20,self.bounds.size.height/2)];
//        _distanceLable.backgroundColor = [UIColor clearColor];
//        _distanceLable.textAlignment = NSTextAlignmentLeft;
//        _distanceLable.textColor = [UIColor blackColor];
//        _distanceLable.font = [UIFont systemFontOfSize:11];
//        [self addSubview:_distanceLable];
//        
        self.backgroundColor = [UIColor clearColor];
        isHighLight = NO;
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = self.bounds;
        [button setImage:[UIImage imageNamed:@"location.png"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(clickMarkerView) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        
        typeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(13, 13, 25, 25)];
        typeImageView.backgroundColor = [UIColor clearColor];
        [typeImageView setImage:[UIImage imageNamed:image]];
        [self addSubview:typeImageView];
    }
    return self;
}


//Touch ended -> showing info view with animation. 
- (void)clickMarkerView {
    
    if (self.superview) {
        [self.superview bringSubviewToFront:self];
    }
    if (_delegate && [_delegate respondsToSelector:@selector(touchedPOIItem:markerView:)]) {
        [_delegate performSelector:@selector(touchedPOIItem:markerView:) withObject:_poiItem withObject:self];
    }
}

- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
    
}

//- (void)drawRect:(CGRect)rect {
//    CGContextRef contextRef = UIGraphicsGetCurrentContext();
//    
//    CGContextSetRGBFillColor(contextRef, 0, 0, 0, 0.3);
//    CGRect rectangle = CGRectMake(0,0,self.bounds.size.width,self.bounds.size.height/2);
//    CGContextFillRect(contextRef, rectangle);
//    
//    CGContextSetRGBFillColor(contextRef, 255, 255, 255, 0.3);
//    CGRect rectangle2 = CGRectMake(0,self.bounds.size.height/2,self.bounds.size.width,self.bounds.size.height/2);
//    CGContextFillRect(contextRef, rectangle2);
//    
//    if (self.isHighLight) {
//        CGContextSetRGBFillColor(contextRef, 1, 0, 0, 0.3);
//        CGRect rectangle = self.bounds;
//        CGContextFillRect(contextRef, rectangle);
//    } else {
//        CGContextSetFillColorWithColor(contextRef, [UIColor clearColor].CGColor);
//        CGRect rectangle = self.bounds;
//        CGContextFillRect(contextRef, rectangle);
//    }
//    
//    
//}

- (void)setIsHighLight:(BOOL)isHighLight_ {
    isHighLight = isHighLight_;
    [self setNeedsDisplay];
}

@end
